package com.maimao.model.order.input;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.maimao.model.es.EsBoolConvert;
import com.maimao.model.es.anno.*;
import com.maimao.model.order.es.EsOrder;
import com.maimao.model.order.es.EsOrderGoods;
import com.maimao.model.order.es.EsOrderShop;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.time.LocalDateTime;

import static com.maimao.model.order.es.EsOrder.*;
import static com.maimao.model.order.es.EsOrderShop.*;
import static com.maimao.model.order.es.EsOrderGoods.*;

/**
 * 订单搜索条件 所有状态类字段 如果不查询则传空 原使用-1作为【全部】标识已废弃
 *
 * @author MaoLin Wang
 * @date 2021/1/22 1:42 下午
 */
@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class OrderSearchInput implements Serializable {

    private static final long serialVersionUID = 9026879424734845514L;
    /**
     * 商品标题
     */
    @EsSearchFiled(nested = true, nestedPath = ORDER_GOODS_NESTED_PATH, fieldName = EsOrderGoods.TITLE, matchQuery = true, matchOperatorAnd = true)
    private String title;

    @EsSearchFiled(fieldName = EsOrder.ID)
    private Long orderId;

    @EsSearchFiled(fieldName = EsOrder.USER_ID)
    private String userId;

    /**
     * 评价类型 null 全部 1 已评价 0 未评价
     */
    @EsSearchFiled(fieldName = COMMENT, nested = true, nestedPath = ORDER_GOODS_NESTED_PATH, valueConvert = EsBoolConvert.class)
    private Integer commentType;

    /**
     * 买家昵称，商家订单搜索用 【导出时不使用】
     */
    private String buyerName;

    /**
     * 商品编号 商家订单搜索用
     */
    @EsSearchFiled(fieldName = GOODS_ID, nested = true, nestedPath = ORDER_GOODS_NESTED_PATH)
    private Long goodsId;

    /**
     * 店铺id 当前登录的商家店铺id
     */
    @EsSearchFiled(fieldName = SHOP_ID,nested = true,nestedPath = ORDER_SHOP_NESTED_PATH)
    private Long shopId;


    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss", iso = DateTimeFormat.ISO.DATE_TIME)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @EsSearchFiled(fieldName = FIELD_CREATE_TIME, isRangeQuery = true)
    private LocalDateTime fromTime;

    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss", iso = DateTimeFormat.ISO.DATE_TIME)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @EsSearchFiled(fieldName = FIELD_CREATE_TIME, isRangeQuery = true)
    private LocalDateTime toTime;

    /**
     * 精确搜索
     */
    @EsSearchFiled(fieldName = SHOP_NAME, nested = true, nestedPath = ORDER_SHOP_NESTED_PATH)
    private String shopName;

    /**
     * 交易状态 orderShop的
     */
    @EsSearchFiled(fieldName = EsOrderShop.STATUS, nested = true, nestedPath = ORDER_SHOP_NESTED_PATH)
    private Integer status;

    /**
     * 发货状态 orderGoods的
     */
    @EsSearchFiled(fieldName = SHIPPED_STATUS, nested = true, nestedPath = ORDER_GOODS_NESTED_PATH)
    private Integer shippedStatus;

    /**
     * 是否收货 shippedStatus=1 receive=0 ===> 待收货 【导出时不使用】
     */
    private Integer receive;

    @EsSearchFiled(fieldName = DELETED, valueConvert = EsBoolConvert.class)
    private Integer deleted;


    /**
     * true：商家导出，则需要设置shopId为当前登录的商家店铺id false: 不处理
     */
    private boolean shopOrder;

    /**
     * 用户导出
     */
    private boolean userOrder;

    @Override
    public String toString() {
        return "OrderSearchInput{" +
                "title='" + title + '\'' +
                ", orderId=" + orderId +
                ", commentType=" + commentType +
                ", buyerName='" + buyerName + '\'' +
                ", goodsId=" + goodsId +
                ", shopId=" + shopId +
                ", fromTime=" + fromTime +
                ", toTime=" + toTime +
                ", shopName='" + shopName + '\'' +
                ", status=" + status +
                ", shippedStatus=" + shippedStatus +
                ", receive=" + receive +
                ", deleted=" + deleted +
                ", shopOrder=" + shopOrder +
                '}';
    }
}
